Lab assignment 5
Part 1
-
Identify 4 mebers of Java Collection Class or Interfaces
- List
- Set
- Queue
- Stack
-
Analyse these 4 by explaining two key characteristics of each
-
List
- Can allow duplicate elements.
- Allows you to have null elements.
-
Set
- Does not allow duplicate elements.
- Models a matheatical set.
-
Queue
- First element that enters a queue is the first one to be removed.
- There are two different classes that are used to implement the queue interface.
-
Stack
- First element that enters a stack is the last one to be removed.
- Has methods like push(E item) and pop(E item).
-
Part 2
-
What is your understanding of types in traingle braces.
- It specifies the data type of element that can be placed in the interface.
- String represents the string class, which will only allow strings to be placed in the List interface.
- String and Integer represent the key-value paring for the map interface.
-
This is legal because the ArrayList collection implements the List interface.
-
ArrayList and LinkedList both implement the list interface as general purpose implementations.CopyOnWriteArrayList is a special-purpose list implementation. Classes like HashMap, TreeMap, and LinkedMap are implementations of the Map interface.
--- title: Animal example --- classDiagram note "From Duck till Zebra" Animal <|-- Duck note for Duck "can fly\ncan swim\ncan dive\ncan help in debugging" Animal <|-- Fish Animal <|-- Zebra Animal : +int age Animal : +String gender Animal: +isMammal() Animal: +mate() class Duck{ +String beakColor +swim() +quack() } class Fish{ -int sizeInFeet -canEat() } class Zebra{ +bool is_wild +run() }